 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import queenb.net.entitybean.L200;
import queenb.web.inteface.L200Inf;
import queenb.web.store.L200Store;
import queenb.web.util.ContextUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class L200Controller extends QueenbController {

    private int pn100;  // Id nhan vien
    private Date ld201;
    private Date ld202;
    private int ln203;
    private int ln204;
    private int ln205;
    private int ln206;
    private int ln207;
    private String lv208;
    private int ln209;
    private int ln210;
    private String lv211;
    private String lv212;
    private int ln213;
    private String lv214;
    private String lv224;
    private L200Inf l200Inf;
    private L200Store l200Store;
    private String temp = "";
    private String temp_active = "display:none;";
    private List<L200> listL200N;
    private boolean flagedit;
    private boolean renderAdd;
    private String ln203st;
    private String ln204st;
    private String ln205st;
    private String ln213st;
    private String ln207st;
    private String messageform = "";
    private String reloadPage;
    private List<L200> listoftabL200 = new ArrayList<L200>();
            

    public L200Controller() {
        this.setTemp("display:block");
        l200Store = new L200Store();
        Object objPN100 = getRequest().getParameter("pn100");
        if (objPN100 != null) {
            this.pn100 = Integer.parseInt(objPN100.toString());
        }
        System.out.println("--------------- id------" + pn100);
        //Chu y khong dung chung duoc cac bien da dat o tren
        Object pn100N = getRequest().getParameter("id");
        Object pn100A = getRequest().getParameter("pn100A");
        Object pn100E = getRequest().getParameter("pn100E");
        Object pl100E = getRequest().getParameter("pl100E");
        if (pn100N != null) {
            this.pn100 = Integer.parseInt(pn100N.toString());
            // Tung lam cho form load ajax
            
        }
        if (getRequest().getParameter("action") != null) {
            String action = getRequest().getParameter("action");
            if (action.equals("add")) {
                this.pn100 = Integer.parseInt(pn100A.toString());
                this.flagedit = true;
            }
            if (action.equals("edit")) {
                this.pn100 = Integer.parseInt(pn100E.toString());

                this.flagedit = true;

            }
//            if (action.equals("saveL200")) {
//
//                this.pn100 = EmployeeController.idEmp;
//            }
        }
        if (pn100N != null) {
            this.pn100 = Integer.parseInt(pn100N.toString());
            listL200N = getListAllL200ById(pn100);
            if (listL200N != null && listL200N.size() > 0) {
                renderAdd = false;
                System.out.println("---render---" + renderAdd + "----" + listL200N.size());
            } else {
                renderAdd = true;
                System.out.println("---render---" + renderAdd + "----" + listL200N.size());
            }
        } else {
            listL200N = getListAllL200ById(pn100);
        }
    }

    public void saveL200() throws ParseException {

        System.out.println("---flagedit-ds--" + flagedit);
        String date = ContextUtil.getRequestParameter("leavedate1");
        if (!date.equals("")) {
            setLd201(Util.parseDate(date, "dd/MM/yyyy"));
        } else {
            setLd201(null);
        }

        date = ContextUtil.getRequestParameter("leavedate2");
        if (!date.equals("")) {
            setLd202(Util.parseDate(date, "dd/MM/yyyy"));
        } else {
            setLd202(null);
        }


        //bổ sung 10/2/2012 xét trường hợp bằng null..... Edit: KHOA
        if (!"".equals(ln203st)) {
            ln203 = Integer.parseInt(ln203st.replaceAll(",", "").trim());
        }
        if (!"".equals(ln204st)) {
            ln204 = Integer.parseInt(ln204st.replaceAll(",", "").trim());
        }
        if (!"".equals(ln205st)) {
            ln205 = Integer.parseInt(ln205st.replaceAll(",", "").trim());
        }
        if (!"".equals(ln213st)) {
            ln213 = Integer.parseInt(ln213st.replaceAll(",", "").trim());
        }
        if (!"".equals(ln207st)) {
            ln207 = Integer.parseInt(ln207st.replaceAll(",", "").trim());
        }

        System.out.println("---aaaaaaaaaaaa" + this.getPn100() + "," + Util.toSQLDate(this.getLd201()) + "," + Util.toSQLDate(this.getLd202()) + "," + this.getLn203() + "," + this.getLn204() + "," + this.getLn205() + "," + this.getLn206() + "," + this.getLn207() + "," + this.getLv208() + "," + this.getLn209() + "," + this.getLn210() + "," + this.getLv211() + "," + this.getLv212() + "," + this.getLn213() + "," + this.getLv224() + "," + getLogin().getUserName());

        int count = l200Store.updateL200By(this.getPn100(), Util.toSQLDate(this.getLd201()), Util.toSQLDate(this.getLd202()), this.getLn203(), this.getLn204(), this.getLn205(), this.getLn206(), this.getLn207(), this.getLv208(), this.getLn209(), this.getLn210(), this.getLv211(), this.getLv212(), this.getLn213(), this.getLv214(), null, null, this.getLv224(), getLogin().getUserName());
        if (count > 0) {
            
            if (flagedit == true) {
              //  sendRedirectURL("employee.jsp", getPn100(), 2);
                 sendRedirectUrlTab("employeenew.jsp?tab=itemcontent"+getPn100()+"&linkEmp="+ Util.convertMD5(getRequest().getRequestURI()));
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                setMessageform(getResourceString("success"));
            }
        } else {
            if (flagedit == true) {
             //   sendRedirectURL("employee.jsp", getPn100(), 2);
                  sendRedirectUrlTab("employeenew.jsp?tab=itemcontent"+getPn100()+"&linkEmp="+ Util.convertMD5(getRequest().getRequestURI()));
                showGlobalReport(true, getResourceString("datasuccessfail"));
            } else {
                setMessageform(getResourceString("error"));
            }
        }

        // }

        // bỏ 10/2/2012.... edit: KHOA
        //sendRedirectURL("employee.jsp", getPn100(), 2);
        //  int count = l200Inf.updateL200By(56,0,'12/12/2012',null,400,0,300,"inset demo",null,null,getLogin().getUserName());
    }

    public List<L200> getListAllL200ById(int id) {
        try {
            // int pn1000 = EmployeeController.getPnPN100Detail();
            System.out.println("--list---" + id + "," + 0 + "," + getLogin().getUserName());
            List<L200> listL200 = l200Store.findl200(getLogin().getCompanyNo(), id, getLogin().getUserName());
            if (listL200.size() > 0) {
                Iterator icIterator = listL200.iterator();
                while (icIterator.hasNext()) {
                    L200 l200 = (L200) icIterator.next();
                    this.pn100 = l200.getFn100();
//                    this.ln203 = l200.getLn203();
//                    this.ln204 = l200.getLn204();
                    this.ln205 = l200.getLn205();
                    this.ln206 = l200.getLn206();
                    this.ln207 = l200.getLn207();
                    this.ln209 = l200.getLn209();
                    this.ln210 = l200.getLn210();
                    this.ln213 = l200.getLn213();
                    this.lv208 = l200.getLv208();
                    this.lv211 = l200.getLv211();
                    this.lv212 = l200.getLv212();
                    this.ld201 = l200.getLd201();
                    this.lv224 = l200.getLv224();
                    this.lv214 = l200.getLv214();

                    double ln213db = Util.convertStringToDouble(String.valueOf(l200.getLn213()));
                    ln213st = Util.numberformater(ln213db, "##,###,###");
                    System.out.println("-------ln203---" + ln213st);

                    double ln203db = Util.convertStringToDouble(String.valueOf(l200.getLn203()));
                    ln203st = Util.numberformater(ln203db, "##,###,###");
                    System.out.println("-------ln203---" + ln203st);

                    double ln204db = Util.convertStringToDouble(String.valueOf(l200.getLn204()));
                    ln204st = Util.numberformater(ln204db, "##,###,###");

                    double ln205db = Util.convertStringToDouble(String.valueOf(l200.getLn205()));
                    ln205st = Util.numberformater(ln205db, "##,###,###");

                    double ln207db = Util.convertStringToDouble(String.valueOf(l200.getLn207()));
                    ln207st = Util.numberformater(ln207db, "##,###,###");
                }

            } else {
                // this.pn100 = pn1000;
            }
            return listL200;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }
    }

    public int deleteL200(int id) {
        if (id != 0) {
            int rows = 0;
            rows = l200Store.deleteL200(id, getLogin().getUserName());
            return rows;
        } else {
            return 0;
        }

    }

    /**
     * @return the l200Inf
     */
    public L200Inf getL200Inf() {
        return l200Inf;
    }

    /**
     * @param l200Inf the l200Inf to set
     */
    public void setL200Inf(L200Inf l200Inf) {
        this.l200Inf = l200Inf;
    }

    /**
     * @return the temp
     */
    public String getTemp() {
        return temp;
    }

    /**
     * @param temp the temp to set
     */
    public void setTemp(String temp) {
        this.temp = temp;
    }

    /**
     * @return the temp_active
     */
    public String getTemp_active() {
        return temp_active;
    }

    /**
     * @param temp_active the temp_active to set
     */
    public void setTemp_active(String temp_active) {
        this.temp_active = temp_active;
    }

    /**
     * @return the listL200
     */
    public List<L200> getListL200N() {
        if (listL200N != null) {
            renderAdd = true;
        } else {
            renderAdd = false;
        }

        return listL200N;
    }

    /**
     * @param listL200 the listL200 to set
     */
    public void setListL200N(List<L200> listL200N) {
        this.listL200N = listL200N;
    }

    /**
     * @return the flagedit
     */
    public boolean isFlagedit() {
        return flagedit;
    }

    /**
     * @param flagedit the flagedit to set
     */
    public void setFlagedit(boolean flagedit) {
        this.flagedit = flagedit;
    }

    /**
     * @return the pn100
     */
    public int getPn100() {
        return pn100;
    }

    /**
     * @param pn100 the pn100 to set
     */
    public void setPn100(int pn100) {
        this.pn100 = pn100;
    }

    /**
     * @return the ld201
     */
    public Date getLd201() {
        return ld201;
    }

    /**
     * @param ld201 the ld201 to set
     */
    public void setLd201(Date ld201) {
        this.ld201 = ld201;
    }

    /**
     * @return the ld202
     */
    public Date getLd202() {
        return ld202;
    }

    /**
     * @param ld202 the ld202 to set
     */
    public void setLd202(Date ld202) {
        this.ld202 = ld202;
    }

    /**
     * @return the ln203
     */
    public int getLn203() {
        return ln203;
    }

    /**
     * @param ln203 the ln203 to set
     */
    public void setLn203(int ln203) {
        this.ln203 = ln203;
    }

    /**
     * @return the ln204
     */
    public int getLn204() {
        return ln204;
    }

    /**
     * @param ln204 the ln204 to set
     */
    public void setLn204(int ln204) {
        this.ln204 = ln204;
    }

    /**
     * @return the ln205
     */
    public int getLn205() {
        return ln205;
    }

    /**
     * @param ln205 the ln205 to set
     */
    public void setLn205(int ln205) {
        this.ln205 = ln205;
    }

    /**
     * @return the ln206
     */
    public int getLn206() {
        return ln206;
    }

    /**
     * @param ln206 the ln206 to set
     */
    public void setLn206(int ln206) {
        this.ln206 = ln206;
    }

    /**
     * @return the ln207
     */
    public int getLn207() {
        return ln207;
    }

    /**
     * @param ln207 the ln207 to set
     */
    public void setLn207(int ln207) {
        this.ln207 = ln207;
    }

    /**
     * @return the lv208
     */
    public String getLv208() {
        return lv208;
    }

    /**
     * @param lv208 the lv208 to set
     */
    public void setLv208(String lv208) {
        this.lv208 = lv208;
    }

    /**
     * @return the ln209
     */
    public int getLn209() {
        return ln209;
    }

    /**
     * @param ln209 the ln209 to set
     */
    public void setLn209(int ln209) {
        this.ln209 = ln209;
    }

    /**
     * @return the ln210
     */
    public int getLn210() {
        return ln210;
    }

    /**
     * @param ln210 the ln210 to set
     */
    public void setLn210(int ln210) {
        this.ln210 = ln210;
    }

    /**
     * @return the lv211
     */
    public String getLv211() {
        return lv211;
    }

    /**
     * @param lv211 the lv211 to set
     */
    public void setLv211(String lv211) {
        this.lv211 = lv211;
    }

    /**
     * @return the lv212
     */
    public String getLv212() {
        return lv212;
    }

    /**
     * @param lv212 the lv212 to set
     */
    public void setLv212(String lv212) {
        this.lv212 = lv212;
    }

    /**
     * @return the lv224
     */
    public String getLv224() {
        return lv224;
    }

    /**
     * @param lv224 the lv224 to set
     */
    public void setLv224(String lv224) {
        this.lv224 = lv224;
    }

    /**
     * @return the ln213
     */
    public int getLn213() {
        return ln213;
    }

    /**
     * @param ln213 the ln213 to set
     */
    public void setLn213(int ln213) {
        this.ln213 = ln213;
    }

    /**
     * @return the renderAdd
     */
    public boolean isRenderAdd() {
        return renderAdd;
    }

    /**
     * @param renderAdd the renderAdd to set
     */
    public void setRenderAdd(boolean renderAdd) {
        this.renderAdd = renderAdd;
    }

    /**
     * @return the ln203st
     */
    public String getLn203st() {

        return ln203st;
    }

    /**
     * @param ln203st the ln203st to set
     */
    public void setLn203st(String ln203st) {
        this.ln203st = ln203st;
    }

    /**
     * @return the ln204st
     */
    public String getLn204st() {
        return ln204st;
    }

    /**
     * @param ln204st the ln204st to set
     */
    public void setLn204st(String ln204st) {
        this.ln204st = ln204st;
    }

    /**
     * @return the ln205st
     */
    public String getLn205st() {
        return ln205st;
    }

    /**
     * @param ln205st the ln205st to set
     */
    public void setLn205st(String ln205st) {
        this.ln205st = ln205st;
    }

    /**
     * @return the ln213st
     */
    public String getLn213st() {
        return ln213st;
    }

    /**
     * @param ln213st the ln213st to set
     */
    public void setLn213st(String ln213st) {
        this.ln213st = ln213st;
    }

    /**
     * @return the ln207st
     */
    public String getLn207st() {
        return ln207st;
    }

    /**
     * @param ln207st the ln207st to set
     */
    public void setLn207st(String ln207st) {
        this.ln207st = ln207st;
    }

    /**
     * @return the messageform
     */
    public String getMessageform() {
        return messageform;
    }

    /**
     * @param messageform the messageform to set
     */
    public void setMessageform(String messageform) {
        this.messageform = messageform;
    }

    /**
     * @return the lv214
     */
    public String getLv214() {
        return lv214;
    }

    /**
     * @param lv214 the lv214 to set
     */
    public void setLv214(String lv214) {
        this.lv214 = lv214;
    }

    /**
     * @return the reloadPage
     */
    public String getReloadPage() {
        return reloadPage;
    }

    /**
     * @param reloadPage the reloadPage to set
     */
    public void setReloadPage(String reloadPage) {
        this.reloadPage = reloadPage;
    }

    /**
     * @return the listoftabL200
     */
    public List<L200> getListoftabL200() {
        try {
            if(SessionProvider.getSessionMapValue("PN100HD")!=null){
                pn100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
             System.out.println("----------THAM SO-----L200------"+getLogin().getCompanyNo()+","+ pn100+","+ getLogin().getUserName());
            listoftabL200 = l200Store.findl200(getLogin().getCompanyNo(), pn100, getLogin().getUserName());
              System.out.println("-----SIZE---------"+listoftabL200.size());
        } catch (Exception e) {
        }
        return listoftabL200;
    }

    /**
     * @param listoftabL200 the listoftabL200 to set
     */
    public void setListoftabL200(List<L200> listoftabL200) {
        this.listoftabL200 = listoftabL200;
    }
}
